{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 本代码用来给指定的根据指定的csv文件生成对应的特征列"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1. 导入包"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np  \n",
    "import pandas as pd\n",
    "import math\n",
    "import os\n",
    "from scipy.fftpack import fft,ifft\n",
    "import matplotlib.pyplot as plt\n",
    "import matplotlib.axes as axes\n",
    "from tqdm import tqdm"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2. 定义特征获取函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [],
   "source": [
    "def getFeatures(acc_list,LEN):\n",
    "    FFT_list = []\n",
    "    \n",
    "    for i in tqdm(range(acc_list.size)):\n",
    "        start32 = i - LEN if i>= LEN else 0\n",
    "        if i == 0:\n",
    "            FFT = {\"skewFFT\":0,\"kurtFFT\":0,\"maxFFT\":0,\"max_indexFFT\":0,\"engyFFT\":0,\"centroidFFT\":0,\"entropyFFT\":0,\"fft\":None}\n",
    "        else:\n",
    "            FFT = FFT_get(acc_list[start32:i],LEN)\n",
    "        FFT_list.append(FFT)\n",
    "            \n",
    "    avg_list = acc_list.rolling(window=LEN,min_periods=1).apply(np.mean,raw=True)\n",
    "    std_list = acc_list.rolling(window=LEN,min_periods=1).apply(np.std,raw=True)\n",
    "    max_list= acc_list.rolling(window=LEN,min_periods=1).apply(np.max,raw=True)\n",
    "    min_list = acc_list.rolling(window=LEN,min_periods=1).apply(np.min,raw=True)\n",
    "    media_list = acc_list.rolling(window=LEN,min_periods=1).apply(np.median,raw=True)\n",
    "    quantile_list = acc_list.rolling(window=LEN,min_periods=1).quantile(quantile=0.75,interpolation=\"nearest\")-acc_list.rolling(window=LEN,min_periods=1).quantile(quantile=0.25,interpolation=\"nearest\")\n",
    "\n",
    "    rms_list = rms(avg_list,std_list)\n",
    "    engy_list = acc_list.rolling(window=LEN,min_periods=1).apply(engy,raw=True)\n",
    "    skew_list= acc_list.rolling(window=LEN,min_periods=1).skew().values\n",
    "    kurt_list= acc_list.rolling(window=LEN,min_periods=1).kurt().values\n",
    "\n",
    "    return {\"avg\":avg_list,\"std\":std_list,\"max\":max_list,\"min\":min_list,\"med\":media_list,\"iqr\":quantile_list,\"rms\":rms_list,\"engy\":engy_list,\"skw\":skew_list,\"krt\":kurt_list,\"FFT\":FFT_list}\n",
    "\n",
    "def FFT_get(acc_list,LEN):\n",
    "    fft_list = abs(fft(acc_list)[:int(acc_list.size/2)])/(acc_list.size/2)\n",
    "    if fft_list.size != LEN/2:\n",
    "        return {\"skewFFT\":0,\"kurtFFT\":0,\"maxFFT\":0,\"max_indexFFT\":0,\"engyFFT\":0,\"centroidFFT\":0,\"entropyFFT\":0,\"fft\":fft_list}\n",
    "    fft_list[0]=0\n",
    "    skew = pd.DataFrame(fft_list).skew().values\n",
    "    kurt = pd.DataFrame(fft_list).kurt().values\n",
    "    ma_x = np.max(fft_list)\n",
    "    max_index = (list(fft_list).index(ma_x)/(acc_list.size/2))*16\n",
    "    engyFFT = engy(fft_list)\n",
    "    centroid = Centroid(fft_list)\n",
    "    entropy = Entropy(fft_list)\n",
    "    return  {\"skewFFT\":skew,\"kurtFFT\":kurt,\"maxFFT\":ma_x,\"max_indexFFT\":max_index,\"engyFFT\":engyFFT,\"centroidFFT\":centroid,\"entropyFFT\":entropy,\"fft\":fft_list}\n",
    "\n",
    "def rms(acc_list_1,acc_list_2):\n",
    "    pow_1st = pd.Series([pow(indiv,2) for indiv in acc_list_1])\n",
    "    pow_2nd = pd.Series([pow(indiv,2) for indiv in acc_list_2])\n",
    "    pow_sum = pow_1st+pow_2nd\n",
    "    return [math.sqrt(indiv) for indiv in pow_sum]\n",
    "\n",
    "def engy(data):\n",
    "    return np.sum([pow(point,2) for point in data])/data.size\n",
    "\n",
    "def Entropy(data):\n",
    "\n",
    "    \n",
    "def Centroid(data):\n",
    "    sum1=0\n",
    "    sum2=0\n",
    "    for i in range(data.size):\n",
    "        sum1+=pow(data[i],2)\n",
    "        sum2+=pow(data[i],2)*i\n",
    "    return (sum2/sum1)/(data.size/16)\n",
    "    "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. 加载文件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>time</th>\n",
       "      <th>us</th>\n",
       "      <th>acc</th>\n",
       "      <th>ws</th>\n",
       "      <th>label</th>\n",
       "      <th>avg</th>\n",
       "      <th>std</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>52:08.4</td>\n",
       "      <td>1012464</td>\n",
       "      <td>0.03598</td>\n",
       "      <td>2.27844</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>52:08.4</td>\n",
       "      <td>1044468</td>\n",
       "      <td>0.03342</td>\n",
       "      <td>2.23848</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>52:08.4</td>\n",
       "      <td>1076472</td>\n",
       "      <td>0.03821</td>\n",
       "      <td>2.43992</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>52:08.5</td>\n",
       "      <td>1108476</td>\n",
       "      <td>0.03703</td>\n",
       "      <td>2.40637</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>52:08.5</td>\n",
       "      <td>1140476</td>\n",
       "      <td>0.03831</td>\n",
       "      <td>2.15383</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      time       us      acc       ws  label  avg  std\n",
       "0  52:08.4  1012464  0.03598  2.27844    NaN  0.0  0.0\n",
       "1  52:08.4  1044468  0.03342  2.23848    NaN  0.0  0.0\n",
       "2  52:08.4  1076472  0.03821  2.43992    NaN  0.0  0.0\n",
       "3  52:08.5  1108476  0.03703  2.40637    NaN  0.0  0.0\n",
       "4  52:08.5  1140476  0.03831  2.15383    NaN  0.0  0.0"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "csv_filename = \"raw data/Printer.csv\"\n",
    "csv_filename_featured = \"printer_featured.csv\"\n",
    "df = pd.read_csv(csv_filename,names=[\"time\",\"us\",\"acc\",\"ws\",\"label\",\"avg\",\"std\"])\n",
    "df.head(5)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = df.drop([\"ws\",\"label\",\"avg\",\"std\"],axis=1)\n",
    "df.head(10)\n",
    "\n",
    "acc_list = df[\"acc\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3. 处理数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [],
   "source": [
    "# for i in getFeatures(acc_list,32)[\"FFT\"]:\n",
    "#     print(i[\"skewFFT\"],i[\"fft\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 7228/7228 [00:07<00:00, 1016.25it/s]\n",
      "100%|██████████| 7228/7228 [00:06<00:00, 1044.14it/s]\n",
      "100%|██████████| 7228/7228 [00:07<00:00, 924.88it/s]\n",
      "100%|██████████| 7228/7228 [00:09<00:00, 795.12it/s]\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>time</th>\n",
       "      <th>us</th>\n",
       "      <th>acc</th>\n",
       "      <th>avg_1</th>\n",
       "      <th>std_1</th>\n",
       "      <th>max_1</th>\n",
       "      <th>min_1</th>\n",
       "      <th>med_1</th>\n",
       "      <th>iqr_1</th>\n",
       "      <th>rms_1</th>\n",
       "      <th>...</th>\n",
       "      <th>rms_8</th>\n",
       "      <th>engy_8</th>\n",
       "      <th>skw_8</th>\n",
       "      <th>krt_8</th>\n",
       "      <th>Fskw_8</th>\n",
       "      <th>Fkrt_8</th>\n",
       "      <th>Fmax_8</th>\n",
       "      <th>FmaxId_8</th>\n",
       "      <th>Fentrp_8</th>\n",
       "      <th>Fcentr_8</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>52:08.4</td>\n",
       "      <td>1012464</td>\n",
       "      <td>0.03598</td>\n",
       "      <td>0.03598</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.03598</td>\n",
       "      <td>0.03598</td>\n",
       "      <td>0.035980</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.035980</td>\n",
       "      <td>...</td>\n",
       "      <td>0.035980</td>\n",
       "      <td>0.001295</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>52:08.4</td>\n",
       "      <td>1044468</td>\n",
       "      <td>0.03342</td>\n",
       "      <td>0.03470</td>\n",
       "      <td>0.001280</td>\n",
       "      <td>0.03598</td>\n",
       "      <td>0.03342</td>\n",
       "      <td>0.034700</td>\n",
       "      <td>0.00256</td>\n",
       "      <td>0.034724</td>\n",
       "      <td>...</td>\n",
       "      <td>0.034724</td>\n",
       "      <td>0.001206</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>52:08.4</td>\n",
       "      <td>1076472</td>\n",
       "      <td>0.03821</td>\n",
       "      <td>0.03587</td>\n",
       "      <td>0.001957</td>\n",
       "      <td>0.03821</td>\n",
       "      <td>0.03342</td>\n",
       "      <td>0.035980</td>\n",
       "      <td>0.00479</td>\n",
       "      <td>0.035923</td>\n",
       "      <td>...</td>\n",
       "      <td>0.035923</td>\n",
       "      <td>0.001290</td>\n",
       "      <td>-0.206082</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>52:08.5</td>\n",
       "      <td>1108476</td>\n",
       "      <td>0.03703</td>\n",
       "      <td>0.03616</td>\n",
       "      <td>0.001768</td>\n",
       "      <td>0.03821</td>\n",
       "      <td>0.03342</td>\n",
       "      <td>0.036505</td>\n",
       "      <td>0.00105</td>\n",
       "      <td>0.036203</td>\n",
       "      <td>...</td>\n",
       "      <td>0.036203</td>\n",
       "      <td>0.001311</td>\n",
       "      <td>-0.886037</td>\n",
       "      <td>0.824385</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>52:08.5</td>\n",
       "      <td>1140476</td>\n",
       "      <td>0.03831</td>\n",
       "      <td>0.03659</td>\n",
       "      <td>0.001800</td>\n",
       "      <td>0.03831</td>\n",
       "      <td>0.03342</td>\n",
       "      <td>0.037030</td>\n",
       "      <td>0.00223</td>\n",
       "      <td>0.036634</td>\n",
       "      <td>...</td>\n",
       "      <td>0.036634</td>\n",
       "      <td>0.001342</td>\n",
       "      <td>-1.158537</td>\n",
       "      <td>0.903630</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 67 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      time       us      acc    avg_1     std_1    max_1    min_1     med_1  \\\n",
       "0  52:08.4  1012464  0.03598  0.03598  0.000000  0.03598  0.03598  0.035980   \n",
       "1  52:08.4  1044468  0.03342  0.03470  0.001280  0.03598  0.03342  0.034700   \n",
       "2  52:08.4  1076472  0.03821  0.03587  0.001957  0.03821  0.03342  0.035980   \n",
       "3  52:08.5  1108476  0.03703  0.03616  0.001768  0.03821  0.03342  0.036505   \n",
       "4  52:08.5  1140476  0.03831  0.03659  0.001800  0.03831  0.03342  0.037030   \n",
       "\n",
       "     iqr_1     rms_1    ...        rms_8    engy_8     skw_8     krt_8 Fskw_8  \\\n",
       "0  0.00000  0.035980    ...     0.035980  0.001295       NaN       NaN      0   \n",
       "1  0.00256  0.034724    ...     0.034724  0.001206       NaN       NaN      0   \n",
       "2  0.00479  0.035923    ...     0.035923  0.001290 -0.206082       NaN      0   \n",
       "3  0.00105  0.036203    ...     0.036203  0.001311 -0.886037  0.824385      0   \n",
       "4  0.00223  0.036634    ...     0.036634  0.001342 -1.158537  0.903630      0   \n",
       "\n",
       "   Fkrt_8  Fmax_8  FmaxId_8  Fentrp_8  Fcentr_8  \n",
       "0       0     0.0       0.0       0.0       0.0  \n",
       "1       0     0.0       0.0       0.0       0.0  \n",
       "2       0     0.0       0.0       0.0       0.0  \n",
       "3       0     0.0       0.0       0.0       0.0  \n",
       "4       0     0.0       0.0       0.0       0.0  \n",
       "\n",
       "[5 rows x 67 columns]"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "features = getFeatures(acc_list,32)\n",
    "df[\"avg_1\"] = features[\"avg\"]\n",
    "df[\"std_1\"] = features[\"std\"]\n",
    "df[\"max_1\"] = features[\"max\"]\n",
    "df[\"min_1\"] = features[\"min\"]\n",
    "df[\"med_1\"] = features[\"med\"]\n",
    "df[\"iqr_1\"] = features[\"iqr\"]\n",
    "df[\"rms_1\"] = features[\"rms\"]\n",
    "df[\"eng_1\"] =features[\"engy\"]\n",
    "df[\"skw_1\"] = features[\"skw\"]\n",
    "df[\"krt_1\"] = features[\"krt\"]\n",
    "df[\"fskw_1\"] = [indiv[\"skewFFT\"] for indiv in features[\"FFT\"]]\n",
    "df[\"fkrt_1\"] = [indiv[\"kurtFFT\"] for indiv in features[\"FFT\"]]\n",
    "df[\"fmax_1\"] = [indiv[\"maxFFT\"] for indiv in features[\"FFT\"]]\n",
    "df[\"fspp_1\"] = [indiv[\"max_indexFFT\"] for indiv in features[\"FFT\"]]\n",
    "df[\"fetp_1\"] = [indiv[\"entropyFFT\"] for indiv in features[\"FFT\"]]\n",
    "df[\"fctd_1\"] = [indiv[\"centroidFFT\"] for indiv in features[\"FFT\"]]\n",
    "\n",
    "features = getFeatures(acc_list,64)\n",
    "df[\"avg_2\"] = features[\"avg\"]\n",
    "df[\"std_2\"] = features[\"std\"]\n",
    "df[\"max_2\"] = features[\"max\"]\n",
    "df[\"min_2\"] = features[\"min\"]\n",
    "df[\"med_2\"] = features[\"med\"]\n",
    "df[\"iqr_2\"] = features[\"iqr\"]\n",
    "df[\"rms_2\"] = features[\"rms\"]\n",
    "df[\"eng_2\"] =features[\"engy\"]\n",
    "df[\"skw_2\"] = features[\"skw\"]\n",
    "df[\"krt_2\"] = features[\"krt\"]\n",
    "df[\"fskw_2\"] = [indiv[\"skewFFT\"] for indiv in features[\"FFT\"]]\n",
    "df[\"fkrt_2\"] = [indiv[\"kurtFFT\"] for indiv in features[\"FFT\"]]\n",
    "df[\"fmax_2\"] = [indiv[\"maxFFT\"] for indiv in features[\"FFT\"]]\n",
    "df[\"fspp_2\"] = [indiv[\"max_indexFFT\"] for indiv in features[\"FFT\"]]\n",
    "df[\"fetp_2\"] = [indiv[\"entropyFFT\"] for indiv in features[\"FFT\"]]\n",
    "df[\"fctd_2\"] = [indiv[\"centroidFFT\"] for indiv in features[\"FFT\"]]\n",
    "\n",
    "features = getFeatures(acc_list,128)\n",
    "df[\"avg_4\"] = features[\"avg\"]\n",
    "df[\"std_4\"] = features[\"std\"]\n",
    "df[\"max_4\"] = features[\"max\"]\n",
    "df[\"min_4\"] = features[\"min\"]\n",
    "df[\"med_4\"] = features[\"med\"]\n",
    "df[\"iqr_4\"] = features[\"iqr\"]\n",
    "df[\"rms_4\"] = features[\"rms\"]\n",
    "df[\"eng_4\"] =features[\"engy\"]\n",
    "df[\"skw_4\"] = features[\"skw\"]\n",
    "df[\"krt_4\"] = features[\"krt\"]\n",
    "df[\"fskw_4\"] = [indiv[\"skewFFT\"] for indiv in features[\"FFT\"]]\n",
    "df[\"fkrt_4\"] = [indiv[\"kurtFFT\"] for indiv in features[\"FFT\"]]\n",
    "df[\"fmax_4\"] = [indiv[\"maxFFT\"] for indiv in features[\"FFT\"]]\n",
    "df[\"fspp_4\"] = [indiv[\"max_indexFFT\"] for indiv in features[\"FFT\"]]\n",
    "df[\"fetp_4\"] = [indiv[\"entropyFFT\"] for indiv in features[\"FFT\"]]\n",
    "df[\"fctd_4\"] = [indiv[\"centroidFFT\"] for indiv in features[\"FFT\"]]\n",
    "\n",
    "features = getFeatures(acc_list,256)\n",
    "df[\"avg_8\"] = features[\"avg\"]\n",
    "df[\"std_8\"] = features[\"std\"]\n",
    "df[\"max_8\"] = features[\"max\"]\n",
    "df[\"min_8\"] = features[\"min\"]\n",
    "df[\"med_8\"] = features[\"med\"]\n",
    "df[\"iqr_8\"] = features[\"iqr\"]\n",
    "df[\"rms_8\"] = features[\"rms\"]\n",
    "df[\"eng_8\"] =features[\"engy\"]\n",
    "df[\"skw_8\"] = features[\"skw\"]\n",
    "df[\"krt_8\"] = features[\"krt\"]\n",
    "df[\"fskw_8\"] = [indiv[\"skewFFT\"] for indiv in features[\"FFT\"]]\n",
    "df[\"fkrt_8\"] = [indiv[\"kurtFFT\"] for indiv in features[\"FFT\"]]\n",
    "df[\"fmax_8\"] = [indiv[\"maxFFT\"] for indiv in features[\"FFT\"]]\n",
    "df[\"fspp_8\"] = [indiv[\"max_indexFFT\"] for indiv in features[\"FFT\"]]\n",
    "df[\"fetp_8\"] = [indiv[\"entropyFFT\"] for indiv in features[\"FFT\"]]\n",
    "df[\"fctd_8\"] = [indiv[\"centroidFFT\"] for indiv in features[\"FFT\"]]\n",
    "\n",
    "df.head(5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4. 保存文件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "## index=0,去掉索引列\n",
    "df.to_csv(csv_filename_featured,index=0,float_format='%.6f')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     0\n",
       "0  0.0\n",
       "1  0.5"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.DataFrame([1,1])-pd.DataFrame([1,0.5])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
